﻿Imports System.Data.OleDb

Public Class aspNet_UsersInRolesManagement
    Inherits ConnectionClass

    Public Sub InsertUserInRole(ByVal userId As Int32, ByVal roleId As Int32)
        Try

            myConnection.Open()
            Dim SqlString As String = "INSERT INTO aspnet_UsersInRoles(UserId,RoleId) VALUES(@f1,@f2)"
            Dim newCmd As OleDbCommand = New OleDbCommand(SqlString, myConnection)
            newCmd.CommandType = CommandType.Text
            newCmd.Parameters.AddWithValue("@f1", userId)
            newCmd.Parameters.AddWithValue("@f2", roleId)
            newCmd.ExecuteNonQuery()
            myConnection.Close()

        Catch ex As Exception

        End Try
    End Sub


    Public Function SelectCheckUserRoleExistance(ByVal userId As Int32, ByVal roleId As Int32) As Int32
        Try

        
        myConnection.Open()
        Dim Cmd As OleDbCommand = New OleDbCommand("Select Top 1 UserId from aspnet_UsersInRoles where UserId = @f1 and RoleId =@f2", myConnection)
        Cmd.Parameters.AddWithValue("@f1", userId)
        Cmd.Parameters.AddWithValue("@f2", roleId)
        Dim dr = Cmd.ExecuteReader()
        dr.Read()
        If (dr.HasRows) Then
            Return 1
        Else
            Return 0
        End If
        myConnection.Close()
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

End Class
